﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Public;
using System.Data;

namespace WebsiteAdmin
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                Cookie.AdminLogOut();
            }
        }

        protected void Submit_ServerClick(object sender, EventArgs e)
        {
            //string userCode;

            string userName = this.UserName.Value.ToString().ToLower();
            string userPwd = this.UserPwd.Value.ToString().ToLower();
            //userCode = this.UserCode.Value.ToString();
            try
            {
                Bll.Admin admin = new Bll.Admin();
                DataTable dtAdmin = admin.Login(Global.ConSalomon, userName, userPwd);

                if (dtAdmin.Rows.Count > 0)                 //登录成功
                {

                    this.ErrText.Text = "";
                    //Cookie赋值
                    Cookie.AdminID = Convert.ToInt32(dtAdmin.Rows[0]["PKID"]);
                    Cookie.AdminLoginName = dtAdmin.Rows[0]["AdminName"].ToString();
                    WebSession.IsAuthorized = true;
                    Response.Redirect("SkipPage.aspx");

                }
                else
                {
                    this.ErrText.Text = "用户名或密码错误";
                }
            }
            catch (Exception ex)
            {
                this.ErrText.Text = ex.Message;
            }
        }
    }
}
